package com.easou.ps.master.knowledge;

import java.util.List;

import org.apache.log4j.Logger;

import com.easou.ps.thrift.ks.KnowledgeSearchResponse;
import com.easou.ps.webmaster.SearchRequest;
import com.easou.ps.webmaster.SearchResponse;
import com.easou.ps.webmaster.SearchResult;

public class KnowledgeUtils {
	private static final Logger LOG = Logger.getLogger("search");

	public static void toAddKnowledge2Response(SearchResponse response, SearchRequest request, List<KnowledgeSearchResponse> ksResults){
		KnowledgeSearchResponse kResponse = ksResults.get(0);
		
		if(kResponse==null || kResponse.getTitle()==null || kResponse.getTitle().length()<1){
			LOG.error("kResponse is invalid.");
			return ;
		}
		
		SearchResult searchResult = new SearchResult();
		try {
			searchResult.putToExtendFields("workerType", "knowledge");
			searchResult.setTitle(kResponse.getTitle());
			searchResult.setSummary(kResponse.getSummary());
			searchResult.setType("knowledge");
//			searchResult.setSubResult(ksResults.get);
			searchResult.setKsResponse(kResponse);
			
			response.getResults().add(0, searchResult);
		} catch (Exception e) {
			LOG.error("com.easou.ps.master.knowledge.KnowledgeUtils.toAddKnowledgeResult error : "+e);
			return ;
		}
	}
}
